<?php
/*
Plugin Name: HTML Page Sitemap
Plugin URI: http://www.pluginspodcast.com/plugins/html-page-sitemap/
Description: <a href="http://www.pluginspodcast.com/plugins/html-page-sitemap/" target="_blank">HTML Page Sitemap</a> Adds an HTML (Not XML) sitemap of your blog pages (not posts) by entering the shortcode [html-sitemap]. A plugin from <a href="http://www.pluginspodcast.com/" target="_blank">Plugins: The WordPress Plugins Podcast</a>.
Version: 1.1.1
Author: Angelo Mandato
Author URI: http://www.pluginspodcast.com/
Change Log:
	See readme.txt for complete change log

Contributors:
	Angelo Mandato, CIO RawVoice and host of the PluginsPodcast.com - Plugin author
	
Copyright 2009=2010 Angelo Mandato, host of the Plugins Podcast (http://www.pluginspodcast.com)

License: GPL (http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt)
*/


/*
	Add the sitemap when shortcode is encountered
	@param $args - arguments or attributes specified in the shortcode tag.
	@return the page sitemap or empty string if not applicable.
*/
function html_sitemap_shortcode_handler( $args )
{
	if( is_feed() )
		return '';
		
	// Get the nav menu based on the requested menu
	$menu = wp_get_nav_menu_object( $args->menu );

	// Get the nav menu based on the theme_location
	if ( ! $menu && $args->theme_location && ( $locations = get_nav_menu_locations() ) && isset( $locations[ $args->theme_location ] ) )
		$menu = wp_get_nav_menu_object( $locations[ $args->theme_location ] );

     if ( $menu && ! is_wp_error($menu) && !isset($menu_items) ){
         
	$menu_items = wp_get_nav_menu_items($menu->term_id);

	$menu_list = '<ul id="primaryNav" class="col8">';

	foreach ( (array) $menu_items as $key => $menu_item ) {
	    $title = $menu_item->title;
	    $url = $menu_item->url;
	    $menu_list .= '<li><a href="' . $url . '">' . $title . '</a></li>';
	}
	$menu_list .= '</ul>';
    } else {
	$menu_list = '<ul><li>Menu "' . $menu_name . '" not defined.</li></ul>';
    }
    // $menu_list now ready to output

	// Remove the classes added by WordPress

	//return '<ul id="primaryNav" class="col8">'. $html .'</ul>';
    return $menu_list;
}

add_shortcode('html-sitemap', 'html_sitemap_shortcode_handler');

?>